#!/usr/bin/perl -wT
use CGI qw(:standard);
use lib '.';
use users;
use strict;

binmode STDOUT, ":utf8";
#use utf8;
require "doa_subs.pl";


my ($username,$level) = &validate;
my ($realm) = get_realm();
#warn "$username $level";
my $user_level="a User";
if ($level < 10 ) 
{
	$user_level="a Super User";
}
if ($level < 5 ) 
{
	$user_level="an Administrator";
}

print header;
print start_html("Realm Crawler Main Menu");
my $realmdesc=get_realm_desc($realm);
print h2( {-align => "CENTER"}, "Realm Crawler ($realmdesc)");

my $alli_update="0";
my $activity_update="0";
my $map_update="0";
my $map_count=0;
my $player_update="0";

my $alliance_id={};
my $alliance_name={};
my $alli_count=loadAlliance($alliance_id,$alliance_name);

my $player_id={};
my $player_name={};
my $player_count=loadPlayers($player_id,$player_name);

my $outdata={};
my $fdate;
my $ftime;

$outdata=loadMAP("mapfile");
($fdate,$ftime)=pdateTime($outdata->{'update'}{'map'}||"0");
$map_update=$fdate." ".$ftime;
($fdate,$ftime)=pdateTime($outdata->{'update'}{'activity'}||"0");
$activity_update=$fdate." ".$ftime;
($fdate,$ftime)=pdateTime($outdata->{'update'}{'alliance'}||"0");
$alli_update=$fdate." ".$ftime;
($fdate,$ftime)=pdateTime($outdata->{'update'}{'player'}||"0");
$player_update=$fdate." ".$ftime;
my $cityref={};
$cityref=$outdata->{'map'};
$map_count=keys %{$cityref};

print h3( {-align => "CENTER"},"welcome $username - you are logged in as $user_level");


print br();

print <<MYR;

 <table border="1" cellpadding="2" cellspacing="2" height="58"
width="276" align="center">
<tbody>
<tr>
<td align="center" >To change Realm Click <a href="changerealm.pl">here</a><br>
</td>
</tbody>
</table>
MYR

print <<EOF;
 <br>
<hr>
<h3 align="center">Data Statistics</h3>
<table height="112" align="center" border="1" cellpadding="2"
cellspacing="2" width="794">
<tbody>
<tr>
<td valign="top"><br>
</td>
<th>All Alliances<br>
</th>
<th>Player Names</th>
<th>Activity Data</th>
<th>Map Data</th>
</tr>
<tr>
<td align="center" valign="middle">Last Update</td>
<td align="center">$alli_update</td>
<td align="center">$player_update</td>
<td align="center">$activity_update</td>
<td align="center">$map_update</td>
</tr>
<tr>
<td align="center" valign="middle">Record Count<br>
</td>
<td align="center">$alli_count</td>
<td align="center">$player_count</td>
<td align="center"><br>
</td>
<td align="center">$map_count</td>
</tr>
</tbody>
</table>
&nbsp; <br>
<h3 align="center">Below are a number of ways the information held
in the system can be viewed.</h3>
<table height="196" align="center" border="1" cellpadding="2"
cellspacing="2" width="794">
<tbody>
<tr>
<td> To list all known Alliances click <a href="listAlliance2.pl">here</a> </td>
</tr>
<tr>
<td>If you know the name of the alliance you want to find, Enter it in the box below<br>
<form action="findalliance2.pl" method="get"><b>Alliance
Name </b><input name="search" size="30" type="text"> <input
type="submit"></form>
</td>
</tr>
<tr>
<td>If you want to find a particular player (and the system
knows the player name) use this option. (now ignores upper/lower case) <B>If the name has a space, type a space in the box e.g. (m kah) not (m+kah)</B>
<form action="findplayer2.pl" method="get">&nbsp;&nbsp; <b>Player



Name</b> <input name="search" size="30" type="text"> <input
type="submit"><br>
</form>
</td>
</tr>
<tr>
<td valign="top">To list all players who are NOT in an
Alliance click <a href="nonalliance2.pl">here</a> This takes a while to load as there are so many players!!!<br>
</td>
</tr>
<tr>
<td>If you want to list all Non Alliance players with a minimum MIGHT set the minimum here <br>
<form action="nonalliance2.pl" method="get"><b>Minimum Might </b><input name="MLIMIT" size="12" type="text"><b> Maximum Limit</b><input name="XLIMIT" size="12" type="text"><input
type="submit"></form>
</td>
</tr>

</tbody>
</table>
<br>
<hr>
EOF
if ($level <10 )
{
	print h3( {-align => "CENTER"}, "The next three option are for updating the map after scanning it.");
	print <<FOE;
 <table border="1" cellpadding="2" cellspacing="2" height="58"
width="276" align="center">
<tbody>
<tr>
<td>To Upload a map file click <a href="uploadmap2.pl">here</a><br>
</td>
</tr>
<tr>
<td> To Process a map file click <a
href="processmap2.pl">here</a> takes about a minute to show anything on screen<br>
</td>
</tr>
<tr>
<td valign="top">Map Scanner Install help <a
href="/install.html">here</a></td>
</tr>
</tbody>
</table>
<br>
<hr>
FOE

}

if ($level <5 )
{
print <<EOF2;
 <h3 align="center">These options are for Administrators <b>ONLY</b></h3>
<p align="center">If you have created a new Realm, don't forget you need to add the Alliance details BEFORE you add Map data</p>
<table border="1" cellpadding="2" cellspacing="2" height="112"
width="612" align="center">
<tbody>
<tr>
<td>Upload Alliance Details file <a href="uploadalliance2.pl">here</a></td><td>Process Alliance details <a href="update_alliance2.pl">here</a></td>
</tr>
<tr>
<td>Upload an Activity file <a href="uploadactivity2.pl">here</a></td><td>Process Activity update <a href="update_activity2.pl">here</a></td>
</tr>
<tr>
<tr>
<td>&nbsp;</td>
</tr>
<td>User Administration <a
href="admin.pl">here</a></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>Upload a html file to docroot <a
href="uploadhtml2.pl">here</a></td><td>Upload a pl file <a href="uploadpl2.pl">here</a></td>
</tr>
<tr>
<br>
</tr>
<tr>
<td>Upload a data file <a href="uploaddata2.pl">here</a></td>
</tr>
<tr>
<td>Error Log file viewer <a href="Elogviewer2.pl">here</a></td><td>Access Log file viewer <a href="Alogviewer2.pl">here</a></td>
</tr>
</tbody>
</table>
<p> </p>
EOF2
}

print a( {-href=>"logout.cgi"}, "log out of your account");
print br();
print a( {-href=>"/passchg.html"}, "change your password");
print end_html;

